package com.itcast.trade.stock.admin.user.repository;

import com.itcast.bulls.stock.common.utils.GlobalConstants;
import com.itcast.bulls.stock.entity.user.AccountWarnTemplate;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.cache.annotation.CachePut;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;

@RepositoryRestResource(path = "/accountWarnNotifyTemplate")
public interface AccountWarnTemplateRepository extends PagingAndSortingRepository<AccountWarnTemplate, Long>, JpaSpecificationExecutor<AccountWarnTemplate> {

    /**
     * 根据消息类型获取对象
     * @return
     */
    AccountWarnTemplate getDistinctByWarnType(@Param("warnType")int warnType);

    @ApiOperation(value = "根据ID获取预警通知信息")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "ID唯一标识", name = "id", dataType = "Long", required = true)
    })
    AccountWarnTemplate getById(@Param("id")Long id);

    /**
     * 保存数据， 更新缓存
     * @param <S>
     * @return
     */
    @Override
    @CachePut(value = GlobalConstants.ACCOUNT_WARN_TEMPLATE_TYPE_KEY, key = "#a0.warnType")
    <S extends AccountWarnTemplate> S save(S accountWarnTemplate);
}